<?php

/*
 * gpa_new Description
 * date 18 Feb 10
 * time 22:23:41
 * @$package
 * @name controller_screening
 * @filesource controller_screening.php
 * @author Hanny Setiawan
 */

class controller_screening extends Controller
{
    /**
     * @access public
     * @method __construct
     * @param void
     * @return void
     */
    public function  __construct()
    {
        parent::__construct();
        $model_menu = $this->getModel('menu');
        $this->_main_menus = createMenus($model_menu->getMenus());
        $this->_user_menus = createUserMenus();
    }

    public function screening($param)
    {
        if(!User::getUserId()) {
            redirect(getAppUrl('user', 'login'), false);
        }

        if(isset($param[0])) {
            $iid = intval(@$param[0]);
            $var['image_id'] = $iid;
        }

        $var['page_title']="Screening";
        $var['mainmenus'] = $this->_main_menus;
        $var['usermenus'] = $this->_user_menus;

        //var_dump($var);
        //exit;

        $this->addVars($var);
        $this->renderView("screening_html");
    }

    public function ajax_get_images($param)
    {
        if(!User::getUserId()) {
            redirect(getAppUrl('user', 'login'), false);
        }
        
        $get = getInstance('request')->get;
        $page = (intval(@$get['page'])<2?1:$get['page'])-1;
        $jum = intval(!isset($param[0])?getInstance('config')->get('screening_list_images'):$param[0]);

        $model = $this->getModel();
        if(isset($get['iid'])) {
            $var['images'] = $model->getImageFromId($get['iid']);
        } else {
            $var['images'] = $model->getStepOneImages($page, $jum);
        }

        $this->addVars($var);
        $this->renderView("screening_form_html");
    }

    public function point($param) {
        $iid = intval(@$param[0]);
        $post = getInstance('request')->post;

        $return['success'] = true;

        $model = $this->getModel();
        if(!@$model->pointImage($iid, $post['point'], $post['comment'], 1)) {
            $return['success'] = false;
            $return['message'] = 'can\'t point image! please try later!';
        }
        
        echo json_encode($return);
    }

    public function editor() {
        if(!User::getUserId()) {
            redirect(getAppUrl('user', 'login'), false);
        }

        $session = User::getSession();

        if(intval($session['group_id']) != 4) {
            die("not an editor");
        }

        $var['page_title']="Editor Screening";
        $var['mainmenus'] = $this->_main_menus;
        $var['usermenus'] = $this->_user_menus;

        //var_dump($var);
        //exit;

        $this->addVars($var);
        $this->renderView("screening2_html");
    }

    public function ajax_get_editor_screening($param) {
        if(!User::getUserId()) {
            redirect(getAppUrl('user', 'login'), false);
        }

        $session = User::getSession();

        if(intval($session['group_id']) != 4) {
            die("not an editor");
        }

        $get = getInstance('request')->get;
        $page = (intval(@$get['page'])<2?1:$get['page'])-1;
        $jum = intval(!isset($param[0])?getInstance('config')->get('screening_list_images'):$param[0]);

        $model = $this->getModel();
        $var['images'] = $model->getStepTwoImages($page, $jum);

        $this->addVars($var);
        $this->renderView("screening_form_html");
    }

    public function __default()
    {
        redirect('screening/screening');
    }
}

?>